package com.resolution.dietaryassessment.utils;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;

/**
 * @author By Resolusion
 * @Title: 个人信息录入，对textView进行观察
 * @Date: 2020/1/19
 * @Time: 11:12
 * @email Res01ution@foxmail.com
 */
public class JumpTextWatcher implements TextWatcher {
    private EditText mThisView;
    private EditText mNextView;
    private Button mButton;

    public JumpTextWatcher(EditText vThis, EditText vNext ,Button button) {
        super();
        mThisView = vThis;
        mNextView = vNext;
        mButton = button;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        mButton.setOnClickListener(v -> {
            if (mThisView.getText() != null) {
                if (mThisView.isFocused()) {
                    mThisView.clearFocus();
                    mNextView.requestFocus();
                    mNextView.setSelection(mNextView.getText().length());
                }
            }
        });
    }
}
